package com.example.demo.common;

import lombok.Data;

import java.io.Serializable;

/**
 * 普通对象,不需要存储于spring中,用于存储同于对象返回
 *
 * @author CY
 * @date 2023/03/13 22:06
 **/
@Data
public class AjaxResult {
    private Integer code;
    private String msg;
    private Object data;

    /**
     * 操作成功
     */
    public static AjaxResult success(Object data) {
        AjaxResult result = new AjaxResult();
        result.setCode(200);
        result.setMsg("");
        result.setData(data);
        return result;
    }

    public static AjaxResult success(int code, Object data) {
        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setMsg("");
        result.setData(data);
        return result;
    }

    public static AjaxResult success(int code, String msg, Object data) {
        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    /**
     * 操作失败
     */
    public static AjaxResult fail(int code, String msg) {
        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static AjaxResult fail(int code, String msg, Object object) {
        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(object);
        return result;
    }
}
